<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title>选座</title>
<link href="/static/index/images/favicon.ico" type="image/x-icon" rel="shortcut icon" />
<link rel="stylesheet" href="/static/index/css/bootstrap.css">
<style type="text/css">
ul li{list-style: none;border-radius: 10px;}
.demo{width:700px; margin:40px auto 0 auto; min-height:450px;}
@media screen and (max-width: 360px) {.demo {width:340px}}

.front{width: 300px;margin: 5px 32px 45px 32px;background-color: #f0f0f0;   color: #666;text-align: center;padding: 3px;border-radius: 5px;}
.booking-details {float: right;position: absolute;width:300px;height: 450px;top: 60px;left: 800px;}
.booking-details h3 {margin: 5px 5px 0 0;font-size: 16px;}
.booking-details p{line-height:26px; font-size:16px; color:#999}
.booking-details p span{color:#666}
div.seatCharts-cell {color: #182C4E;height: 25px;width: 25px;line-height: 25px;margin: 3px;float: left;text-align: center;outline: none;font-size: 13px;}
/*座位上面的文字效果*/
div.seatCharts-seat {color:#fff;cursor: pointer;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;}
div.seatCharts-row {height: 35px;}
/*座位自然的效果*/
div.seatCharts-seat.available {background-color: #fff;}
/*座位放上时的的效果*/
div.seatCharts-seat.focused {background-color: #fff;border: none;}
/*座位被选中时的效果*/
div.seatCharts-seat.selected {background-color: #ed1941;color:#ed1941;}
/*座位已售时的效果*/
div.seatCharts-seat.unavailable {background-color:#84bf96;cursor: not-allowed;color:#84bf96;}
div.seatCharts-container {border-right: 1px dotted #adadad;width: 400px;padding: 20px;float: left;}
div.seatCharts-legend {padding-left: 0px;position: absolute;bottom: 16px;}
ul.seatCharts-legendList {padding-left: 0px;}
.seatCharts-legendItem{float:left; width:90px;margin-top: 10px;line-height: 2;}
span.seatCharts-legendDescription {margin-left: 5px;line-height: 30px;}
.checkout-button {display: block;width:80px; height:30px; line-height:20px;border:1px solid #999;font-size: 14px; cursor:pointer;border-radius: 10px;background: #6a6da9;color:#fff;}
#selected-seats {max-height: 150px;overflow-y: auto;overflow-x: none;width: 200px;}
#selected-seats li{float:left; width:72px; height:26px; line-height:26px; border:1px solid #d3d3d3; background:#f7f7f7; margin:6px; font-size:14px; font-weight:bold; text-align:center}
</style>

</head>

<body>



<form action="{:url('index/Seat/save')}" method="post">

<div id="main">
   <div class="demo">
        <div id="seat-map" style="background:#ccc;border-radius:10px;width:800px;height:500px;">
            <div class="front">屏幕</div>                 
        </div>
        <div class="booking-details" >
            <p>影片：<span>{$film['filmname']}</span></p>
            <p>影院：<span>{$cinema['cinema']}</span></p>
            <p>时间：<span>{$sort['time']}</span></p>
            <p>座位：</p>
            <ul id="selected-seats"></ul>
            <p>票数：<span id="counter">0</span></p>
            <p>总计：<b>￥<span id="total">0</span></b></p>
            
            <input type="hidden" name="price" value="{$sort['price']}">
            <input type="hidden" name="sort_id" value="{$sort['id']}">
            <input type="hidden" name="filmname" value="{$film['filmname']}">
            <input type="hidden" name="cinema" value="{$cinema['cinema']}">
            <input type="hidden" id="seat" name="seat">

            <button class="btn btn-md btn-info" id="add">确认购买</button>
            <div id="legend"></div>
        </div>
        <div style="clear:both"></div>
   </div>
    
  <br/>
</div>
</form>

<script type="text/javascript" src="/static/index/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/index/js/jquery.seat-charts.min.js"></script>
<script type="text/javascript">
var price = {$sort['price']}; //票价
$(document).ready(function() {
    var $cart = $('#selected-seats'), //座位区
    $counter = $('#counter'), //票数
    $total = $('#total'); //总计金额
    
    var sc = $('#seat-map').seatCharts({
        map: [  //座位图
            {php}
            echo $seat
            {/php}
        ],
        naming : {
            top : false,
            getLabel : function (character, row, column) {
                return column;
            }
        },
        legend : { //定义图例
            node : $('#legend'),
                                
        },
        click: function () { //点击事件
            if (this.status() == 'available') { //可选座
                $('<li>'+(this.settings.row+1)+'排'+this.settings.label+'座</li>')
                    .attr('id', 'cart-item-'+this.settings.id)
                    .data('seatId', this.settings.id)
                    .appendTo($cart);

                $counter.text(sc.find('selected').length+1);
                $total.text(recalculateTotal(sc)+price);
                            
                return 'selected';
            } else if (this.status() == 'selected') { //已选中
                    //更新数量
                    $counter.text(sc.find('selected').length-1);
                    //更新总计
                    $total.text(recalculateTotal(sc)-price);
                        
                    //删除已预订座位
                    $('#cart-item-'+this.settings.id).remove();
                    //可选座
                    return 'available';
            } else if (this.status() == 'unavailable') { //已售出
                return 'unavailable';
            } else {
                return this.style();
            }
        }
    });
    //已售出的座位
    sc.get([{$sell}]).status('unavailable');
        
});
//计算总金额
function recalculateTotal(sc) {
    var total = 0;
    sc.find('selected').each(function () {
        total += price;
    });
    $('#pri').attr('value', $('#total').html())
    return total;

    
}

setInterval(function(){
    var arr = [];
    for (var i = 0; i < $('#selected-seats li').length; i++) {
        arr += $('#selected-seats li').eq(i).attr('id')
    };
    $('#seat').attr('value', arr);
}, 1)
</script>

</body>
</html>